clear all
set matsize 3000

* Install mfx2 for Table 4
ssc install mfx2

****************************************************************************************************************
****************************************************************************************************************
																				
*This do file creates All Tables in the main text of "Repelling Rape: Foreign Direct Investment Empowers Women"

****************************************************************************************************************
****************************************************************************************************************

* Set directory to current folder, which contains 3 subfolders (Data, Program files, & Results).
cd "...........\CrimeFDI_ReplicationFiles_JOP_Jun2024\"


************************************************************
** Table 1: Foreign Direct Investment and Rape, 2002-2012 **
************************************************************
use ".\Data\crimes_2002to12_census_merged.dta", clear

** Generating year dummies and demographic interaction controls
tab year, gen(dumyr)
gen int_pop_03=tot_p*dumyr2
gen int_pop_04=tot_p*dumyr3
gen int_pop_05=tot_p*dumyr4
gen int_pop_06=tot_p*dumyr5
gen int_pop_07=tot_p*dumyr6
gen int_pop_08=tot_p*dumyr7
gen int_pop_09=tot_p*dumyr8
gen int_pop_10=tot_p*dumyr9
gen int_pop_11=tot_p*dumyr10
gen int_pop_12=tot_p*dumyr11

foreach var of varlist d_* {
   forvalues i=2/11 {
      gen c_`var'_`i'=`var'*dumyr`i'
   }
}
** Generating state-specific trends
gen t=0
forvalues i=1/11 {
replace t=`i' if dumyr`i'==1
}
egen statec=group(state)
quietly tab statec, gen(statecode_dum)
for num 1/32: replace statecode_dumX = statecode_dumX*t

** Regression results for Table 1
xtpqml total_rape treatedXpost dumyr2-dumyr11 int_pop_03-int_pop_12 if top5FDI!=1, i(id) fe cluster(id)
outreg2 using ".\Results\RepellingRape_Table1_results.xls", replace
xtpqml total_rape treatedXpost dumyr2-dumyr11 int_pop_03-int_pop_12 c_d_percent_girls* c_d_percent_lit* if top5FDI!=1, i(id) fe cluster(id)
outreg2 using ".\Results\RepellingRape_Table1_results.xls"
xtpqml total_rape treatedXpost dumyr2-dumyr11 int_pop_03-int_pop_12 c_d_percent_girls* c_d_percent_lit* statecode_dum* if top5FDI!=1, i(id) fe cluster(id)
outreg2 using ".\Results\RepellingRape_Table1_results.xls"
xtpqml total_rape treatedXpost dumyr2-dumyr11 int_pop_03-int_pop_12 c_d_percent_girls* c_d_percent_lit* statecode_dum* if top5FDI!=1, i(id) fe cluster(statec)
outreg2 using ".\Results\RepellingRape_Table1_results.xls"


****************************************************************
** Table 2: FDI Reduced Rape, Instrumental Variable Estimates **
****************************************************************
use ".\Data\crimes_2002to12_mltdistFDI_census_merged.dta", clear

** Generating demographic controls interacted with year dummies
tab year, gen(dumyr)
foreach var of varlist d_* {
   forvalues i=2/10 {
      gen c_`var'_`i'=`var'*dumyr`i'
   }
}
** Preparing outcome and other control variables
egen statec=group(state)
gen imp_p=tot_p*rate_pop^((year-2001)/10)
gen tot_f=tot_p/(1+fm_ratio)*fm_ratio
gen imp_f=tot_f*rate_f^((year-2001)/10)
gen rate_rape=total_rape/imp_p*10^6
gen sttr=statec*year

** Regression results for Table 2
xtset id year
log using ".\Results\RepellingRape_Table2_sttr_results", text replace
xtivreg rate_rape (n_fdi= avg_AutomaticFDIMOD sq) c_d_percent_girls* c_d_percent_lit*, fe first
xtivreg rate_rape (n_fdi= avg_AutomaticFDIMOD sq) c_d_percent_girls* c_d_percent_lit* imp_f, fe first
xtivreg rate_rape (n_fdi= avg_AutomaticFDIMOD sq) c_d_percent_girls* c_d_percent_lit* sttr imp_f, fe first
log close


******************************************************************
** Table 3: Foreign Direct Investment and Labor Market Outcomes **
******************************************************************
use ".\Data\Nss55_61_66_Sch10_IndAct_wTreatment.dta", clear

** Merging demographic controls
merge m:1 id year using ".\Data\crimes_2002to12_census_merged.dta", keepus(tot_p d_percent_girls* d_percent_lit*)
keep if year==1999 | year==2004 | year==2009
drop if _merge==2
ren _merge _m_d_demo_control

** Generating demographic controls
gen int_pop_post=tot_p*post
replace int_pop_post=0 if round==55

gen d_percent_lit_post=d_percent_lit*post
replace d_percent_lit_post=0 if round==55

gen d_percent_girls_post=d_percent_girls*post
replace d_percent_girls_post=0 if round==55

** Regression results for Table 3, Columns 1-4
set matsize 800
logit i_working treatedXpost i.round age gen_edu int_pop_post d_percent_lit_post d_percent_girls_post i.id [iw=hhwt] if sex==2 & age>=15 & age<=65 & i_schooling!=1, cluster(id)
outreg2 using ".\Results\RepellingRape_Table3_Col_1to4_results.xls", replace
logit i_working treatedXpost i.round age gen_edu int_pop_post d_percent_lit_post d_percent_girls_post i.id [iw=hhwt] if sex==2 & age>=15 & age<=65 & i_schooling!=1, cluster(statecd)
outreg2 using ".\Results\RepellingRape_Table3_Col_1to4_results.xls"
logit i_working treatedXpost i.round age gen_edu int_pop_post d_percent_lit_post d_percent_girls_post i.id [iw=hhwt] if sex==1 & age>=15 & age<=65 & i_schooling!=1, cluster(id)
outreg2 using ".\Results\RepellingRape_Table3_Col_1to4_results.xls"
logit i_working treatedXpost i.round age gen_edu int_pop_post d_percent_lit_post d_percent_girls_post i.id [iw=hhwt] if sex==1 & age>=15 & age<=65 & i_schooling!=1, cluster(statecd)
outreg2 using ".\Results\RepellingRape_Table3_Col_1to4_results.xls"

areg ln_wage treatedXpost i.round age gen_edu int_pop_post d_percent_lit_post d_percent_girls_post [aw=hhwt] if sex==2 & age>=15 & age<=65 & i_schooling!=1, ab(id) cluster(id)
outreg2 using ".\Results\RepellingRape_Table3_Col_1to4_results.xls"
areg ln_wage treatedXpost i.round age gen_edu int_pop_post d_percent_lit_post d_percent_girls_post [aw=hhwt] if sex==2 & age>=15 & age<=65 & i_schooling!=1, ab(id) cluster(statecd)
outreg2 using ".\Results\RepellingRape_Table3_Col_1to4_results.xls"
areg ln_wage treatedXpost i.round age gen_edu int_pop_post d_percent_lit_post d_percent_girls_post [aw=hhwt] if sex==1 & age>=15 & age<=65 & i_schooling!=1, ab(id) cluster(id)
outreg2 using ".\Results\RepellingRape_Table3_Col_1to4_results.xls"
areg ln_wage treatedXpost i.round age gen_edu int_pop_post d_percent_lit_post d_percent_girls_post [aw=hhwt] if sex==1 & age>=15 & age<=65 & i_schooling!=1, ab(id) cluster(statecd)
outreg2 using ".\Results\RepellingRape_Table3_Col_1to4_results.xls"

** Set up imputed wage estimation regressions
mi set wide
mi register imputed ln_wage

order ln_wage *
mi register regular round - gen_edu

set matsize 10000
mi impute reg ln_wage age sex i.round gen_edu i.id if tot_days!=. & gen_edu!=. & sex!=. & age!=., add(10)

** Regression results for Table 3, Columns 5 and 6
log using ".\Results\RepellingRape_Table3_Col_5n6_results", text
mi estimate: areg ln_wage treatedXpost i.round age gen_edu int_pop_post d_percent_lit_post d_percent_girls_post [pw=hhwt] if tot_days!=. & sex==2 & age>=15 & age<=65 & i_schooling!=1, ab(id) vce(cl id)
mi estimate: areg ln_wage treatedXpost i.round age gen_edu int_pop_post d_percent_lit_post d_percent_girls_post [pw=hhwt] if tot_days!=. & sex==2 & age>=15 & age<=65 & i_schooling!=1, ab(id) vce(cl statecd)
mi estimate: areg ln_wage treatedXpost i.round age gen_edu int_pop_post d_percent_lit_post d_percent_girls_post [pw=hhwt] if tot_days!=. & sex==1 & age>=15 & age<=65 & i_schooling!=1, ab(id) vce(cl id)
mi estimate: areg ln_wage treatedXpost i.round age gen_edu int_pop_post d_percent_lit_post d_percent_girls_post [pw=hhwt] if tot_days!=. & sex==1 & age>=15 & age<=65 & i_schooling!=1, ab(id) vce(cl statecd)
log close


***************************************************************************
** Table 4: Attitudes of Women Towards Women's Participation in Politics **
***************************************************************************
use ".\Data\NES_masterfile_updated.dta", clear

** Probit estimation results for Table 4
probit d_women_politics treated year_dummy treat_2009 if gender1==2,  cluster(unique_id)
mfx2, replace
outreg2 using ".\Results\RepellingRape_Table4_results.xls",  replace
probit d_women_politics treated year_dummy treat_2009 if gender1==2,  cluster(stateid)
mfx2, replace
outreg2 using ".\Results\RepellingRape_Table4_results.xls", append
xi:probit d_women_politics treated year_dummy treat_2009 age i.edlevel1 sc_st hh_members houserooms1 if gender1==2 ,  cluster(unique_id)
mfx2, replace
outreg2 using ".\Results\RepellingRape_Table4_results.xls",  append
xi:probit d_women_politics treated year_dummy treat_2009 age i.edlevel1 sc_st hh_members houserooms1 if gender1==2 ,  cluster(stateid)
mfx2, replace
outreg2 using ".\Results\RepellingRape_Table4_results.xls",  append

probit d_women_politics treated year_dummy treat_2009 if gender1==2 & working_pop==1,  cluster(unique_id)
mfx2, replace
outreg2 using ".\Results\RepellingRape_Table4_results.xls",  append
probit d_women_politics treated year_dummy treat_2009 if gender1==2 & working_pop==1,  cluster(stateid)
mfx2, replace
outreg2 using ".\Results\RepellingRape_Table4_results.xls",  append
xi:probit d_women_politics treated year_dummy treat_2009 age i.edlevel1 sc_st hh_members houserooms1 if gender1==2 & working_pop==1,  cluster(unique_id)
mfx2, replace
outreg2 using ".\Results\RepellingRape_Table4_results.xls",  append
xi:probit d_women_politics treated year_dummy treat_2009 age i.edlevel1 sc_st hh_members houserooms1 if gender1==2 & working_pop==1,  cluster(stateid)
mfx2, replace
outreg2 using ".\Results\RepellingRape_Table4_results.xls",  append

** Linear Fixed-effect regression results for Table 4
areg d_women_politics treated year_dummy treat_2009 if gender1==2  ,absorb(unique_id)  cluster(unique_id)
outreg2 using ".\Results\RepellingRape_Table4_results.xls",  append
areg d_women_politics treated year_dummy treat_2009 if gender1==2  ,absorb(unique_id)  cluster(stateid)
outreg2 using ".\Results\RepellingRape_Table4_results.xls",  append
xi:areg d_women_politics treated year_dummy treat_2009 age i.edlevel1 sc_st hh_members houserooms1 if gender1==2  ,absorb(unique_id)  cluster(unique_id)
outreg2 using ".\Results\RepellingRape_Table4_results.xls",  append
xi:areg d_women_politics treated year_dummy treat_2009 age i.edlevel1 sc_st hh_members houserooms1 if gender1==2  ,absorb(unique_id)  cluster(stateid)
outreg2 using ".\Results\RepellingRape_Table4_results.xls",  append

areg d_women_politics treated year_dummy treat_2009 if gender1==2 & working_pop==1 ,absorb(unique_id)  cluster(unique_id)
outreg2 using ".\Results\RepellingRape_Table4_results.xls",  append
areg d_women_politics treated year_dummy treat_2009 if gender1==2 & working_pop==1 ,absorb(unique_id)  cluster(stateid)
outreg2 using ".\Results\RepellingRape_Table4_results.xls",  append
xi:areg d_women_politics treated year_dummy treat_2009 age i.edlevel1 sc_st hh_members houserooms1 if gender1==2 & working_pop==1 ,absorb(unique_id)  cluster(unique_id)
outreg2 using ".\Results\RepellingRape_Table4_results.xls",  append
xi:areg d_women_politics treated year_dummy treat_2009 age i.edlevel1 sc_st hh_members houserooms1 if gender1==2 & working_pop==1 ,absorb(unique_id)  cluster(stateid)
outreg2 using ".\Results\RepellingRape_Table4_results.xls",  append


*************************************************************
** Table 5: MNC Country of Origin Gender Equality and Rape **
*************************************************************
use ".\Data\crimes_2002to12_census_merged.dta", clear

** Generating year dummies and demographic interaction controls
tab year, gen(dumyr)

gen int_pop_03=tot_p*dumyr2
gen int_pop_04=tot_p*dumyr3
gen int_pop_05=tot_p*dumyr4
gen int_pop_06=tot_p*dumyr5
gen int_pop_07=tot_p*dumyr6
gen int_pop_08=tot_p*dumyr7
gen int_pop_09=tot_p*dumyr8
gen int_pop_10=tot_p*dumyr9
gen int_pop_11=tot_p*dumyr10
gen int_pop_12=tot_p*dumyr11

foreach var of varlist d_* {
   forvalues i=2/11 {
      gen c_`var'_`i'=`var'*dumyr`i'
   }
}

** Generating state-specific trends
gen t=0
forvalues i=1/11 {
replace t=`i' if dumyr`i'==1
}
egen statec=group(state)
quietly tab statec, gen(statecode_dum)
for num 1/32: replace statecode_dumX = statecode_dumX*t

** Merge weighted version of gender equality score.
merge m:m id year using "./Data/gender_weighted.dta"
drop if _merge==2
drop _merge

** Generating interaction term of interest
gen low_gender_eqXpost = low_gender_eq*post

** Regression results for Table 5
xtpqml total_rape low_gender_eq low_gender_eqXpost dumyr2-dumyr11 int_pop_03-int_pop_12 c_d_percent_girls* c_d_percent_lit* statecode_dum* if top5FDI!=1, i(id) fe cluster(id)
outreg2 using ".\Results\RepellingRape_Table5_results.xls", replace
xtpqml total_rape low_gender_eq low_gender_eqXpost dumyr2-dumyr11 int_pop_03-int_pop_12 c_d_percent_girls* c_d_percent_lit* statecode_dum* if top5FDI!=1, i(id) fe cluster(statec)
outreg2 using ".\Results\RepellingRape_Table5_results.xls"
